package com.rentplant.controller;

import com.alibaba.fastjson.JSONObject;
import com.rentplant.Pojo.itemcollect;
import com.rentplant.Pojo.itemcollectanduser;
import com.rentplant.service.impl.itemCollectServiceImp;
import org.apache.tomcat.util.net.jsse.PEMFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/itemCollect")
public class itemCollectController {

    @Autowired
    private itemCollectServiceImp itemcollectserviceimp;

    @RequestMapping("/itemCollect")
//    查看是否收藏物品
    public List<itemcollect> itemCollect(@RequestBody JSONObject req){
        try {
            return itemcollectserviceimp.itemCollect(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //收藏物品
    @RequestMapping("/addItemCollect")
    public boolean addItemCollect(@RequestBody JSONObject req){
        try {
            return itemcollectserviceimp.addItemCollect(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //取消物品收藏
    @RequestMapping("/delItemCollect")
    public boolean delItemCollect(@RequestBody JSONObject req){
        try {
            return itemcollectserviceimp.delItemCollect(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    @RequestMapping("/showItemCollect")
    //展示用户收藏
    public List<itemcollectanduser> showItemCollect(@RequestBody JSONObject req){
        try {
            return itemcollectserviceimp.showItemCollect(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}
